﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using T.ServiceComponent.I18N.SPI;
using T.FAS.Runtime.Term.Dao;
namespace T.FAS.Runtime.Term.Service
{
    public class PageRefManager
    {
        readonly PageRefInstanceLogic instanceLogic = new PageRefInstanceLogic();
        /// <summary>
        /// 重新生成PageJS
        /// </summary>
        /// <returns></returns>
        public long GetPageVerMask(string pageId, string language)
        {
            instanceLogic.RegenerationJSBySource(new List<string> { pageId });
            return 1;
        }
        /// <summary>
        /// 根据词条编号集合获取词条集合
        /// </summary>
        /// <returns></returns>
        public List<I18NPageTermMapping> GetTermsBycodes(List<string> termCodeList)
        {
            Dao.PageTermMappingDao dao = new Dao.PageTermMappingDao();
            List<I18NPageTermMapping> termMapping = dao.GetByCode(termCodeList);

            foreach (var item in termMapping)
            {
                string tid = item.TermID;
                if (!string.IsNullOrEmpty(item.CustomTermID))
                {
                    tid = item.CustomTermID;
                }
                item.TranslateItems = dao.GetByTermId(tid);
            }
            return termMapping;
        }
        /// <summary>
        /// 运行时修改词条，重新生成PageJS 
        /// </summary>
        public void UpdateTermMappings(List<I18NPageTermMapping> i18NPageTerms)
        {
            instanceLogic.UpdateTermMappings(i18NPageTerms);//更新词条信息
        }
        /// <summary>
        /// 重新生成所有JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationAll()
        {
            instanceLogic.RegenerationAll();
        }
        /// <summary>
        /// 根据翻译项生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationJS(List<string> termMappingIDs)
        {
            instanceLogic.RegenerationJS(termMappingIDs);
        }
        /// <summary>
        /// 根据翻译项生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationJSBySource(List<string> sourceIDs)
        {
            instanceLogic.RegenerationJSBySource(sourceIDs);
        }
        /// <summary>
        /// 根据翻译项生成JS
        /// </summary>
        /// <param name="i18NID"></param>
        public void RegenerationBranchJS(string branchID)
        {
            instanceLogic.RegenerationJSByBranch(branchID);
        }
        /// <summary>
        /// 获取公共js新版本
        /// </summary>
        /// <returns></returns>
        public long GetCommonVerMask()
        {
            instanceLogic.RegenerationCommon();
            return 100;
        }
    }
}
